
// Copyright (C) Recursion Company. All rights reserved.

#include "stdafx.h"
#include "vol_user_app_info.h"

//-----------------------------------------------------------------------------------------

CVWnd_SliderBar::CVWnd_SliderBar ()
{
    m_npTickFreq = 1;
    m_npInitialSelStart = m_npInitialSelLength = 0;

    m_npInitialMin = 1;
    m_npInitialMax = 10;
    m_npInitialPageStep = 5;
    m_npInitialLineStep = 1;
    m_npInitialPos = 1;
}

BOOL CVWnd_SliderBar::CreateControl (CVolNativeWndCreateParam* pCreateParam)
{
    if (_CREATE_WND_BY_PARAM (pCreateParam) != NULL)
    {
        ModifyWndStyleEx (this, 0, pCreateParam->m_dwExStyle);

        const INT nInitialMin = (INT)MIN (m_npInitialMin, m_npInitialMax);
        const INT nInitialMax = (INT)MAX (m_npInitialMin, m_npInitialMax);

        SetRange (nInitialMin, nInitialMax, TRUE);

        const INT nRange = nInitialMax - nInitialMin;
        SetLineSize ((INT)CLIP (m_npInitialLineStep, 1, nRange));
        SetPageSize ((INT)CLIP (m_npInitialPageStep, 1, nRange));
        SetTicFreq ((INT)CLIP (m_npTickFreq, 1, nRange));

        SetPos ((INT)CLIP (m_npInitialPos, nInitialMin, nInitialMax));

        if ((pCreateParam->m_dwStyle & TBS_ENABLESELRANGE) != 0)
        {
            SetSelection ((INT)CLIP (m_npInitialSelStart, nInitialMin, nInitialMax),
                    (INT)CLIP (m_npInitialSelStart + m_npInitialSelLength, nInitialMin, nInitialMax));
        }

        return TRUE;
    }

    return FALSE;
}

void CVWnd_SliderBar::OnReflectedHScroll (UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
{
    if (nSBCode != SB_ENDSCROLL && m_pEventListener != NULL)
        m_pEventListener->OnScroll ();
}

void CVWnd_SliderBar::OnReflectedVScroll (UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
{
    if (nSBCode != SB_ENDSCROLL && m_pEventListener != NULL)
        m_pEventListener->OnScroll ();
}
